/* eslint-disable */
<template>
<div class="rating_page">
     <head-top head-title="培训确认" go-back='true'></head-top>
    <div>
      <group label-width="4.5em" label-margin-right="2em" label-align="right">
      <x-textarea :max="500" title= "培训小结" v-model="summary.sum" ></x-textarea>
       <cell title="小结附件" value="summary.attach">
          <!-- <Fileup :vfiles.sync = "summary.attach"></Fileup> -->
              <!-- <a :href="downloadUrl+fl.key+'?attname='+encodeURI(encodeURI(fl.name))" target="_blank" v-for="fl in summary.attach" :key="fl.key" v-text="fl.name"></a> -->
         <cs-avatar :avatar="summary.attach" @newavt="function(data){summary.attach=data}"></cs-avatar>
         <!-- <el-upload class="upload-demo" action="http://up.qbox.me/" >
  <el-button size="small" type="primary">点击上传</el-button>
</el-upload> -->
        </cell>
        <!-- @newavt="function(data){temp.avatar=data}" -->
        <!-- <x-switch title="培训完成" v-model="summary.isFinished"></x-switch> -->
     </group>
    </div>
   <x-button v-if="showButton" mini plain type="primary" @click.native="sumSub()" link="BACK">提交</x-button>
   <x-button  v-if="showButton" mini plain type="warn" link="BACK" >取消</x-button>
</div>
</template>
<script>
import { CellFormPreview, Group, Cell, XButton, XTextarea, XSwitch } from "vux";
import headTop from "src/components/head";
import { getSumDetail, sumUp } from "src/service/actual";
// import Fileup from "@/components/fileup/fileup";
import csAvatar from "@/components/Customer/csAvatar";

export default {
  name: "sumDetail",
  data() {
    return {
    //   sys: "",
      eventId: "",
      code: "",
      userInfo: null,
      task: [],
      showButton: false,
      summary: {
        id: undefined,
        sum: "",
        attach: "",
        // isFinished: undefined,
        code: "",
        name: ""
      },
    //   uploadUrl: process.env.uploadUrl,
    //   downloadUrl: process.env.downloadUrlQn,
      qnUpUrl: process.env.qnUpUrl,
    //   qnDomainUrl: process.env.qnDomainUrl
    };
  },
  components: {
    headTop,
    CellFormPreview,
    Group,
    Cell,
    XButton,
    XTextarea,
    XSwitch,
    // Fileup,
    csAvatar
  },
  mounted() {
    this.getDetail();
  },
  created() {
    this.eventId = this.$route.query.eventId;
    this.userInfo = this.$store.state.user;
    this.code = this.$route.query.code;
    // console.log("created-this.userInfo", this.userInfo);
    this.summary.code = this.userInfo.user_code;
    this.summary.name = this.userInfo.user_name;
  },
  computed: {},
  methods: {
    getDetail() {
      getSumDetail({
        eventId: this.eventId,
        code: this.code
      }).then(response => {
        if (response.status === 200 && response.data.code === 2000) {
          this.summary = response.data.summary;
          //   if (this.summary.isFinished == "1") {
          //     this.summary.isFinished = true;
          //   } else if (this.summary.isFinished == "0") {
          //     this.summary.isFinished = false;
          //   } else {
          //     this.summary.isFinished = false;
          //   }
          this.showButton = false;
          //   console.log("this.summary", this.summary);
        } else if (response.data.code === 2500) {
          this.showButton = true;
          //   console.log("未获取到已提交信息，直接创建???");
          //   console.log(this.eventId);
        } else {
          console.log(response);
          this.$notify({
            title: "失败",
            message: response.status + response.data.msg,
            type: "error",
            duration: 2000
          });
        }
      });
    },
    // shift() {
    //   if (this.summary.isFinished) {
    //     this.summary.isFinished = "1";
    //   } else if (!this.summary.isFinished) {
    //     this.summary.isFinished = "0";
    //   }
    // },
    sumSub() {
      //   this.shift();
      sumUp({
        summary: this.summary,
        actualId: this.eventId
      }).then(response => {
        if (response.status === 200 && response.data.code === 2000) {
          // console.log(this.summary);
          // console.log(response);
          this.$notify({
            title: "成功",
            message: "提交成功",
            type: "success",
            duration: 2000
          });
        } else {
          this.$notify({
            title: "失败",
            message: response.status + response.data.msg,
            type: "error",
            duration: 2000
          });
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
@import "~vux/src/styles/1px.less";
@import "~vux/src/styles/center.less";
.rating_page {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #fff;
  overflow: scroll;
}
</style>
